package com.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.common.utils.base.UuidUtil;
import com.entity.FuJianGuanXi;
import com.entity.XinWenZiXun;
import com.repository.FuJianGuanXiDao;
import com.repository.XinWenZiXunDao;
import com.service.base.BaseServiceImp;

@Service("XinWenZiXunService")
public class XinWenZiXunServiceImp extends BaseServiceImp<XinWenZiXun> implements XinWenZiXunService{

	@Autowired
	private XinWenZiXunDao dao;
	@Autowired
	private FuJianGuanXiDao fujianguanxidao; 
	@Override
	public List<XinWenZiXun> findTree(XinWenZiXun o) {
		// TODO Auto-generated method stub
		return dao.findTree(o);
	}
	
	@Override
	public void insert(XinWenZiXun o) {
		o.setId(UuidUtil.get32UUID());
		super.insert(o);
	}
	
	
	@Transactional
	@Override
	public void insertFj( XinWenZiXun o, String fujianId) {
		String xwId=UuidUtil.get32UUID();
		o.setId(xwId);
		o.setFmtp(fujianId);
		super.insert(o);
		if(!fujianId.equals("")){
			if(fujianId.indexOf(",")>-1){
				String fujianIdArr[] = fujianId.split(",");
				for (int i = 0; i < fujianIdArr.length; i++) {
					FuJianGuanXi fjgx = new FuJianGuanXi();
					fjgx.setId(UuidUtil.get32UUID());
					fjgx.setScr(xwId);
					fjgx.setFjbh(fujianIdArr[i]);
					fujianguanxidao.insert(fjgx);
				}
			}else{
				FuJianGuanXi fjgx = new FuJianGuanXi();
				fjgx.setId(UuidUtil.get32UUID());
				fjgx.setScr(xwId);
				fjgx.setFjbh(fujianId);
				fujianguanxidao.insert(fjgx);
			}
		}
		
	}
}
